﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace RegOnline.Views
{
    public partial class printForm : ChildWindow
    {
        public string Disciplina, Fio, Tema, NomerZach, Kafedra, Gruppa, Kod, ZaglavieTitula, FioPrepod, Kyrs;

        public enum PrintOptions
        {
            All, TitulOnly
        }

        public PrintOptions PO;

        public printForm()
        {
            InitializeComponent();

        }


        public void SetPrintOptions(PrintOptions po = PrintOptions.All)
        {

            PO = po;//lol
            if (PO == PrintOptions.All)
            {
                chZapiska.Visibility = System.Windows.Visibility.Visible;
                chZadanie.Visibility = System.Windows.Visibility.Visible;
                chTitul.Visibility = System.Windows.Visibility.Visible;
                chRecenz.Visibility = System.Windows.Visibility.Visible;
                chEmpty.Visibility = System.Windows.Visibility.Visible;

                chZapiska.IsChecked =  true;
                chZadanie.IsChecked =true;
                chTitul.IsChecked = true;
                chRecenz.IsChecked = true;
                chEmpty.IsChecked = false;




            }
            if (PO == PrintOptions.TitulOnly)
            {
                chZapiska.Visibility = System.Windows.Visibility.Collapsed;
                chZadanie.Visibility = System.Windows.Visibility.Collapsed;
                chTitul.Visibility = System.Windows.Visibility.Visible;
                chRecenz.Visibility = System.Windows.Visibility.Collapsed;

                chEmpty.Visibility = System.Windows.Visibility.Visible;

                chZapiska.IsChecked = false;
                chZadanie.IsChecked = false;
                chTitul.IsChecked = true;
                chRecenz.IsChecked = false;
                chEmpty.IsChecked = false;
            }
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog SFD = new SaveFileDialog();
            SFD.Filter = " html - файл |*.html";
            SFD.FilterIndex = 1;
            PrintHtmlForms pf = new PrintHtmlForms();
            if (!chEmpty.IsChecked.Value)
            {
                pf.fio = Fio;
                pf.grup = Gruppa;
                pf.kod = Kod;
                pf.tema = Tema;
                pf.kafedara = Kafedra;
                pf.tipTitula = ZaglavieTitula;
                pf.rukovoditelRaboti = FioPrepod;
                pf.RegNumber = RegNumber;
                pf.RegDate = RegDate;
                pf.Specialnost = Specialnost;
                pf.Facultet = Facultet;
                pf.disciplina = Disciplina;

                pf.rukovoditelRaboti = FioPrepod;
                pf.Kurs = Kyrs;
                pf.NomerZach = NomerZach;
            }
            else
            {
                pf.fio = "";
                pf.grup = "";
                pf.kod = "";
                pf.tema = "";
                pf.kafedara = "";
                pf.tipTitula = "";
                pf.rukovoditelRaboti = "";
                pf.RegNumber = "";
                pf.RegDate = "";
                pf.Specialnost = "";
                pf.Facultet = "";
                pf.disciplina = "";

                pf.rukovoditelRaboti = "";
                pf.Kurs = "";
                pf.NomerZach = "";
            }


               
                if ((bool)SFD.ShowDialog())
                {
                   
                    using (StreamWriter SW = new StreamWriter(SFD.OpenFile(), Encoding.UTF8))
                    {
                        SW.Write(pf.openHtml);
                        if (chTitul.IsChecked.Value) SW.Write(pf.GenerateTitul());
                        if (chZapiska.IsChecked.Value) SW.Write(pf.GenerateZapiska());
                        if (chZadanie.IsChecked.Value) SW.Write(pf.GenerateZadanie());
                        if (chRecenz.IsChecked.Value) SW.Write(pf.GenerateCard());
                        

                        SW.Write(pf.closeBody);
                        SW.Flush();
                    }

            }


            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        public string RegNumber { get; set; }

        public string RegDate { get; set; }

        public string Specialnost { get; set; }

        public string Facultet { get; set; }
    }
}

